/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

/**
 *
 * @author PA
 * @version 2010
 */
public class VistaDeJoc extends JFrame {

    /**
     * @param args
     */
    private static final long serialVersionUID = 8164970557352288581L;
    private ZonaDeJoc zonaJoc;
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout(5, 5);

    // Construir el marco
    public VistaDeJoc() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        jugar();
    }

    public void jugar() {
        zonaJoc.jugar();
    }

    // Inicialización de componentes
    private void jbInit() throws Exception {
        this.setSize(new Dimension(ZonaDeJoc.ANCHO, ZonaDeJoc.ALTO + 20));
        this.setTitle("Joc");
        contentPane = (JPanel) this.getContentPane();
        zonaJoc = new ZonaDeJoc();
        contentPane.setLayout(borderLayout1);
        // Afegim la zona de Joc al JPanel
        //getContentPane().add(zonaJoc, BorderLayout.CENTER);
        getContentPane().add(zonaJoc, BorderLayout.CENTER);
        // Centrar la ventana
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        setLocation((screenSize.width - frameSize.width) / 2,
                (screenSize.height - frameSize.height) / 2);
        setVisible(true);
        // No es pot canviar de mida
        setResizable(false);

        // Transparent 16 x 16 pixel cursor image.
        BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);

        // Create a new blank cursor.
        Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
                cursorImg, new Point(0, 0), "blank cursor");

        // Set the blank cursor to the JFrame.
        this.getContentPane().setCursor(blankCursor);

    }

    // Modificado para poder salir cuando se cierra la ventana
    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        new VistaDeJoc();
    }
}
